//
//  SEPatientFileHealthViewModel.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/29.
//

import UIKit

class SEPatientFileHealthViewModel: SEBaseViewModel {

    var patientViewModel = SEPatientDetailViewModel()

    var models = [SEPatientFileHealthModel]()

    var selectedModel = SEPatientFileHealthModel()

    // MARK: - APIRequest

    /// 患者档案列表
    func requestPatientFileList() {
        SEHttpManager.shared.request(SEProfileAPI.patientFileList(naturalPersonId: patientViewModel.model.mpi, pageNum: page, pageSize: pageSize), model: SEPatientFileHealthListModel.self, withLoading: false) { model, status in
            switch status {
            case .success:
                if self.page == 1 {
                    self.models = model?.list ?? []
                } else {
                    self.models.append(contentsOf: model?.list ?? [])
                }
                self.hasMore = self.models.count < model?.total ?? 0
            default:
                self.page == 1 ? (self.page = 1) : (self.page -= 1)
            }
            self.updateData?(status)
        }
    }
}
